<template>
    <div class='recovery'>
        <div class="container">
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="search-con">
                <el-form-item label="输入搜索：" prop="key" style="margin-right:25px;">
                    <el-input v-model="queryParams.key" placeholder="商品名称/商品货号" clearable size="small" />
                </el-form-item>
                <el-form-item label="商品分类" prop="key_order_type" style="margin-right:25px;">
                    <el-select v-model="queryParams.key_order_type" placeholder="请选择" clearable size="small">
                        <el-option v-for="dict in statusList" :key="dict.dictValue" :label="dict.dictLabel"
                            :value="dict.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="商品品牌" prop="key_order_type" style="margin-right:25px;">
                    <el-select v-model="queryParams.key_order_type" placeholder="请选择" clearable size="small">
                        <el-option v-for="dict in statusList" :key="dict.dictValue" :label="dict.dictLabel"
                            :value="dict.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    <!-- <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
                        v-hasPermi="['customer:manage:export']">导出
                    </el-button> -->
                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="22">
                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="title='新增';handleShow='add'" v-hasPermi="['user:depart:add']">
                        新增</el-button>
                </el-col> -->
                <el-col :span="22">
                    <el-button type="primary" icon="el-icon-edit" size="mini"
                        @click="handleBulk" v-hasPermi="['customer:manage:add']">
                        批量修改</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight
                :height="tableList.length > 0 ? '900px' : '120px'" @selection-change="handleSelectionChange"
                @row-click="toggleSelection">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="编号" align="center" prop="id" />
                <el-table-column label="商品图片" align="center" prop="thumb">
                    <template slot-scope="scope">
                        <div v-if="scope.row.thumb" class="img-list">
                            <el-image style="width: 40px; height: 40px;border:1px solid #eee;border-radius: 50%;" :src="scope.row.thumb"
                                :preview-src-list="[scope.row.thumb]">
                            </el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="商品名称" align="center" prop="account" />
                <el-table-column label="商品分类" align="center" prop="amount" />
                <el-table-column label="价格" align="center" prop="pay_way" />
                <el-table-column label="货号" align="center" prop="source" />
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.status == 0" icon="el-icon-refresh-left" size="mini" type="text" @click="handleAble(scope.row)"
                            v-hasPermi="['basic:history:stop']">还原
                        </el-button>
                        <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                            v-hasPermi="['user:depart:del']">
                            删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="pageCount > 0" :pageCount="pageCount" :page.sync="queryParams.page"
                :limit.sync="queryParams.limit" @pagination="getList" />
        </div>
    </div>
</template>
<script>
import { getSectorLists, setSector, setSectorStatus, delSector } from "@/api/user/department.js"

import { commentStatus } from "@/api/dictionary"

import throttle from 'lodash.throttle'
export default {
    name: 'recovery',
    props: {

    },
    data() {
        return {
            showSearch: true,
            loading: false,
            pageCount: 0,
            total: 0,
            queryParams: {
                page: 1,
                limit: 20,
                key: null,
            },
            tableList: [],
            statusList: commentStatus,
            handleShow: "",
            formLoading: false,
            form: {
                id: null,
                name: null,
            },
            rules: {
                name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
            },
            title: "",
            size: 'mini',
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            // this.loading = true;
            // getSectorLists(this.queryParams).then(res => {
            //     this.tableList = res.data.lists;
            //     this.pageCount = res.data.pageCount;
            //     this.loading = false;
            // });
        },
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        toggleSelection(row) {
            this.$refs.tableList.toggleRowSelection(row);
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectData = selection;
        },
        handleBulk(ids) {
            this.$confirm('是否确认批量修改?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("修改成功");
            })
        },
         /** 导出按钮操作 */
         handleExport() {
                const queryParams = this.queryParams;
                this.$confirm('是否确认导出所有数据项?', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    // return exportBanner(queryParams);
                }).then((response) => {
                    // this.download(response.msg);
                });
            },
        close() {
            this.form = {}
            this.handleShow = ""
        },
        handleAble(row) {
            // let label = row.status == 0 ? '隐藏' : '显示';
            this.$confirm(`是否将“${row.name}”还原?`, "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return setSectorStatus({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess(`${label}成功`);
            })
        },
        handleDelete(row) {
            this.$confirm('是否确认删除' + '"' + row.name + '"' + '?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("删除成功");
            })
        },

        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.formLoading = true;
                    setSector(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        this.close()
                        this.formLoading = false;
                        this.getList();
                    }).catch(() => {
                        this.formLoading = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
.decs {

    /deep/.el-descriptions--mini.is-bordered .el-descriptions-item__cell {
        padding: 0 10px;
    }

    /deep/.el-descriptions-item__cell {
        padding-left: 8px;
        font-size: 14px;
    }

    /deep/ .el-col {
        margin: 0px;
        padding: 0px;
        height: 30px;
        line-height: 30px;
    }

    /deep/.el-form-item__error {
        top: 21%;
        right: 5% !important;
        left: unset;
    }
}

.p {
    font-size: 14px;
}</style>
